<template>

</template>

<script>
import Vue from 'vue'
import Component from 'class-component'
import axios from 'axios'
import { setToken } from '~/utils/auth'

@Component
export default class Login extends Vue {
  user = {
    userName: 'GUEST',
    password: '123456'
  }
  mounted () {
    let self = this
    axios.post('/hpi/login', this.user).then((res) => {
      setToken(res.data)
      self.$store.dispatch('setUser', res.data)
      self.$router.push({path: '/chart/spreadMapSimple'})
    }).catch((error) => {
      let message = error.message
      if (error.response.data) {
        message = (error.response.data.message || message)
      }
      throw new Error(message)
    })
  }
}
</script>

